home *** CD-ROM | disk | FTP | other *** search
/ Image Compendium / Image Compendium.iso / viewer / dos / stripgif.arc / STRIPGIF.C next >
C/C++ Source or Header  |  1988-02-27  |  1KB  |  64 lines

  1. /*****************************************************************************
  2. *                                                                            *
  3. *               Program to remove yecchy stuff before GIF header             *
  4. *                                                                            *
  5. *****************************************************************************/
  6.  
  7. #include <stdio.h>
  8.  
  9. main(ac,av)
  10. int ac;
  11. char *av[];
  12. {
  13.   static char id[] = "GIF87a";    /* GIF header string to look for */
  14.   char *cp;
  15.   int c;
  16.   FILE *fp1,*fp2,*fopen();
  17.  
  18.   /**  Verify command line parameters  **/
  19.  
  20.   if (ac<3) {
  21.     printf("Usage is  STRIPGIF infile outfile\n");
  22.     exit(1);
  23.   }
  24.  
  25.   /**  Attempt to open "infile"  **/
  26.  
  27.   fp1=fopen(av[1],"rb");
  28.   if (!fp1) {
  29.     printf("Unable to open %s\n",av[1]);
  30.     exit(1);
  31.   }
  32.  
  33.   /**  Search for GIF header  **/
  34.  
  35.   cp=id;
  36.   while ((c=getc(fp1))>=0) {
  37.     if (c==*cp) {
  38.       cp++;
  39.       if (!(*cp)) break;
  40.     } else cp=id;
  41.   }
  42.  
  43.   /**  If header was not found then print error message  **/
  44.  
  45.   if (c<0) {
  46.     printf("No valid GIF file found!\n");
  47.     fclose(fp1);
  48.     exit(1);
  49.   }
  50.  
  51.   /**  Otherwise copy header and rest of infile to outfile  **/
  52.  
  53.   fp2=fopen(av[2],"wb");
  54.   if (!fp2) {
  55.     printf("Unable to create %s\n",av[2]);
  56.     fclose(fp1);
  57.     exit(1);
  58.   }
  59.   fprintf(fp2,"%s",id);
  60.   while ((c=getc(fp1))>=0) putc(c,fp2);
  61.   fclose(fp2);
  62.   fclose(fp1);
  63. }
  64.